using System;
using LambdaGp.Core;

namespace LambdaGp.Operators.Functions.MathFunctions
{
    public class Div : BinaryFunction
    {
        public Div()
            : base("/")
        {
        }

        protected override Func<double> CompileBinaryToFunc(Individual individual, Func<double> first, Func<double> second)
        {
            return
                () =>
                {
                    double divisor = second();
                    if (divisor == 0)
                    {
                        divisor = 0.000001;
                    }

                    return first() / divisor;
                };
        }
    }
}
